<template>
  <PageWrapper :class="prefixCls" title="卡片列表-分页">
    <template #headerContent>
      基于Vue Next, TypeScript, Ant Design Vue实现的一套完整的企业级后台管理系统。
      <div :class="`${prefixCls}__link`">
        <a>
          <Icon icon="bx:bx-paper-plane" color="#1890ff" /><span>开始</span>
        </a>
        <a>
          <Icon icon="carbon:warning" color="#1890ff" /><span>简介</span>
        </a>
        <a>
          <Icon icon="ion:document-text-outline" color="#1890ff" /><span>文档</span>
        </a>
      </div>
    </template>

    <div :class="`${prefixCls}__content`">
      <a-list :pagination="paginationConfig">
        <a-row :gutter="16">
          <template v-for="item in tabDataList" :key="item.title">
            <a-col :span="6">
              <a-list-item>
                <a-card :hoverable="true" :class="`${prefixCls}__card`">
                  <div :class="`${prefixCls}__card-title`">
                    <Icon class="icon" v-if="item.icon" :icon="item.icon" :color="item.color" />
                    {{ item.title }}
                  </div>
                  <div :class="`${prefixCls}__card-detail`"> 基于Vue Next, TypeScript, Ant Design Vue实现的一套完整的企业级后台管理系统 </div>
                </a-card>
              </a-list-item>
            </a-col>
          </template>
        </a-row>
      </a-list>
    </div>
  </PageWrapper>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import Icon from '/@/components/Icon/index';
import { cardList } from './listData';
import { PageWrapper } from '/@/components/Page';
import { Card, Row, Col, List } from 'ant-design-vue';

export default defineComponent({
  components: {
    Icon,
    PageWrapper,
    [Card.name]: Card,
    [List.name]: List,
    [List.Item.name]: List.Item,
    [Row.name]: Row,
    [Col.name]: Col,
  },
  setup() {

    //数据
    const data = ref([]);

    //分页相关
    const pageNo = ref(1);
    const pageSize = ref(5);
    const total = ref(0);
    const paginationConfig = ref({
      showSizeChanger: false,
      showQuickJumper: true,
      pageSize,
      current: pageNo,
      total,
      showTotal: (total) => `总 ${total} 条`,
      onChange: handlePageChange,
      onShowSizeChange: pageSizeChange,
    });
    const tabDataList = ref([]);

    onMounted(() => {
      loadData();
    });


    // 获取分页数据
    async function loadData() {
      const { current, pageSize } = paginationConfig.value;
      
      // 模拟 API 请求（实际替换为你的 API 调用）
      let response = current === 5 ?[] : cardList;
      tabDataList.value = response;
      total.value = 100; // 更新总条数
      // const response = await mockApiRequest(current, pageSize);
      // tabDataList.value = response.data;
      // total.value = response.total; // 更新总条数
    }

    // 页码变化时触发
    function handlePageChange(p, pz) {
      pageNo.value = p;
      pageSize.value = pz;
      loadData(); // 重新请求数据
    }

    //跳转到指定页面
    function pageSizeChange(current, size) {
      pageSize.value = size;
      loadData();
    }

    return {
      prefixCls: 'list-card',
      list: cardList,
      tabDataList,
      paginationConfig,
    };
  },
});
</script>
<style lang="less" scoped>
.list-card {
  &__link {
    margin-top: 10px;
    font-size: 14px;

    a {
      margin-right: 30px;
    }

    span {
      margin-left: 5px;
    }
  }

  &__card {
    width: 100%;
    margin-bottom: -8px;

    .ant-card-body {
      padding: 16px;
    }

    &-title {
      margin-bottom: 5px;
      font-size: 16px;
      font-weight: 500;
      color: @text-color;

      .icon {
        margin-top: -5px;
        margin-right: 10px;
        font-size: 38px !important;
      }
    }

    &-detail {
      padding-top: 10px;
      padding-left: 30px;
      font-size: 14px;
      color: @text-color-secondary;
    }
  }
}
</style>
